package com.kang.controller;

import com.kang.entity.SysUser;
import com.kang.service.UserService;
import com.kang.util.WebResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "用户个人信息接口")
@RequestMapping("/user/information")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("查询当前用户信息")
    @GetMapping("selectUser")
    public WebResponse selectUser(HttpServletRequest request) {
        try {
            return WebResponse.resSuccess("查询当前用户信息成功",userService.selectUser(request));
        } catch (Exception ex) {
            log.error("查询当前用户信息失败",ex);
            return WebResponse.resFail("查询当前用户信息失败",null);
        }
    }

    @ApiOperation("获取用户头像")
    @GetMapping("selectUserHeadUrl")
    public WebResponse selectUserHeadUrl(HttpServletRequest request) {
        try {
            return WebResponse.resSuccess("获取用户头像成功",userService.selectUserHeadUrl(request));
        } catch (Exception ex) {
            log.error("获取用户头像失败",ex);
            return WebResponse.resFail("获取用户头像失败",null);
        }
    }

    @ApiOperation("修改用户信息")
    @PostMapping("updateUserInformation")
    public WebResponse updateUserInformation(@RequestBody SysUser sysUser,HttpServletRequest request) {
        try {
            return WebResponse.resSuccess("修改用户信息成功",userService.updateUserInformation(sysUser,request));
        } catch (Exception ex) {
            log.error("修改用户信息失败",ex);
            return WebResponse.resFail("修改用户信息失败",null);
        }
    }

}
